<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>阿里百炼大模型测试平台</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        .container {
            width: 100%;
            max-width: 900px;
            background: white;
            border-radius: 16px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            overflow: hidden;
        }

        header {
            background: linear-gradient(90deg, #3498db, #2c3e50);
            color: white;
            padding: 25px;
            text-align: center;
        }

        h1 {
            font-size: 28px;
            margin-bottom: 10px;
        }

        .subtitle {
            font-size: 16px;
            opacity: 0.9;
        }

        .main-content {
            display: flex;
            padding: 0;
            height: 500px;
        }

        .input-section {
            flex: 1;
            padding: 25px;
            border-right: 1px solid #eee;
            display: flex;
            flex-direction: column;
        }

        .output-section {
            flex: 1;
            padding: 25px;
            background: #f9fafc;
            display: flex;
            flex-direction: column;
        }

        .section-title {
            font-size: 18px;
            margin-bottom: 15px;
            color: #2c3e50;
            display: flex;
            align-items: center;
        }

        .section-title i {
            margin-right: 10px;
            color: #3498db;
        }

        textarea {
            width: 100%;
            flex: 1;
            padding: 15px;
            border: 1px solid #ddd;
            border-radius: 8px;
            resize: none;
            font-size: 16px;
            margin-bottom: 15px;
            transition: border 0.3s;
        }

        textarea:focus {
            outline: none;
            border-color: #3498db;
            box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
        }

        .button-group {
            display: flex;
            gap: 10px;
        }

        button {
            padding: 12px 20px;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-weight: 600;
            transition: all 0.3s;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .send-btn {
            background: #3498db;
            color: white;
            flex: 1;
        }

        .send-btn:hover {
            background: #2980b9;
        }

        .clear-btn {
            background: #e74c3c;
            color: white;
        }

        .clear-btn:hover {
            background: #c0392b;
        }

        .examples {
            margin-top: 20px;
        }

        .examples h3 {
            font-size: 16px;
            margin-bottom: 10px;
            color: #7f8c8d;
        }

        .example-list {
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

        .example-item {
            padding: 10px;
            background: #f3f7fb;
            border-radius: 6px;
            cursor: pointer;
            font-size: 14px;
            transition: background 0.2s;
        }

        .example-item:hover {
            background: #e8f0f8;
        }

        .response-container {
            flex: 1;
            overflow-y: auto;
            padding: 15px;
            background: white;
            border: 1px solid #eee;
            border-radius: 8px;
            margin-bottom: 15px;
        }

        .response-content {
            font-size: 16px;
            line-height: 1.6;
            white-space: pre-wrap;
        }

        .status-bar {
            display: flex;
            justify-content: space-between;
            color: #7f8c8d;
            font-size: 14px;
        }

        .loading {
            display: none;
            align-items: center;
            color: #3498db;
        }

        .loading i {
            margin-right: 8px;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        .success {
            color: #27ae60;
        }

        .error {
            color: #e74c3c;
        }

        @media (max-width: 768px) {
            .main-content {
                flex-direction: column;
                height: auto;
            }

            .input-section {
                border-right: none;
                border-bottom: 1px solid #eee;
            }
        }
    </style>
</head>
<body>
<div class="container">
    <header>
        <h1>阿里百炼大模型测试平台</h1>
        <div class="subtitle">测试与阿里百炼大模型的交互</div>
    </header>

    <div class="main-content">
        <div class="input-section">
            <div class="section-title">
                <i class="fas fa-question-circle"></i>
                <span>输入问题</span>
            </div>
            <textarea id="question-input" placeholder="请输入您的问题..."></textarea>

            <div class="button-group">
                <button class="send-btn" id="send-btn">
                    <i class="fas fa-paper-plane"></i>
                    发送
                </button>
                <button class="clear-btn" id="clear-btn">
                    <i class="fas fa-trash"></i>
                    清空
                </button>
            </div>

            <div class="examples">
                <h3>示例问题：</h3>
                <div class="example-list">
                    <div class="example-item">请介绍一下阿里百炼平台的主要功能</div>
                    <div class="example-item">如何用Java实现一个快速排序算法？</div>
                    <div class="example-item">解释一下人工智能和机器学习的区别</div>
                    <div class="example-item">写一篇关于夏季健康饮食的短文</div>
                </div>
            </div>
        </div>

        <div class="output-section">
            <div class="section-title">
                <i class="fas fa-reply"></i>
                <span>模型响应</span>
            </div>
            <div class="response-container">
                <div class="response-content" id="response-content">
                    <!-- 响应内容将在这里显示 -->
                </div>
            </div>

            <div class="status-bar">
                <div class="loading" id="loading-indicator">
                    <i class="fas fa-spinner"></i>
                    <span>请求中...</span>
                </div>
                <div class="status" id="status-text">就绪</div>
            </div>
        </div>
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        const questionInput = document.getElementById('question-input');
        const sendBtn = document.getElementById('send-btn');
        const clearBtn = document.getElementById('clear-btn');
        const responseContent = document.getElementById('response-content');
        const loadingIndicator = document.getElementById('loading-indicator');
        const statusText = document.getElementById('status-text');
        const exampleItems = document.querySelectorAll('.example-item');

        // 示例问题点击事件
        exampleItems.forEach(item => {
            item.addEventListener('click', () => {
                questionInput.value = item.textContent;
            });
        });

        // 清空按钮事件
        clearBtn.addEventListener('click', () => {
            questionInput.value = '';
            responseContent.textContent = '';
            statusText.textContent = '已清空';
            statusText.className = 'status';
            setTimeout(() => {
                statusText.textContent = '就绪';
            }, 1500);
        });

        // 发送请求事件
        sendBtn.addEventListener('click', async () => {
            const question = questionInput.value.trim();
            if (!question) {
                statusText.textContent = '请输入问题';
                statusText.className = 'status error';
                return;
            }

            // 显示加载状态
            loadingIndicator.style.display = 'flex';
            statusText.textContent = '请求中...';
            statusText.className = 'status';
            sendBtn.disabled = true;

            try {
                // 调用后端API
                const response = await fetch(`/ai/bailian/agent/call?message=${encodeURIComponent(question)}`);

                if (!response.ok) {
                    throw new Error(`请求失败: ${response.status}`);
                }

                const data = await response.text();

                // 显示响应
                responseContent.textContent = data;
                statusText.textContent = '请求成功';
                statusText.className = 'status success';
            } catch (error) {
                console.error('Error:', error);
                responseContent.textContent = `错误: ${error.message}`;
                statusText.textContent = '请求失败';
                statusText.className = 'status error';
            } finally {
                loadingIndicator.style.display = 'none';
                sendBtn.disabled = false;
            }
        });

        // 支持按Enter键发送
        questionInput.addEventListener('keypress', (e) => {
            if (e.key === 'Enter' && !e.shiftKey) {
                e.preventDefault();
                sendBtn.click();
            }
        });
    });
</script>
</body>
</html>